package client.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

import packets.server.UserDetails;

import client.logic.GuiFacade;
import encription.SecurityHandler;


/**
 * a panel which shows a user's details
 * his name , birth day , country , city and picture 
 */
public class pnlUserDetails extends JPanel {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private JButton btnBack;
	private JLabel txtName;
	private JScrollPane jScrollPane1;
	private JPanel jPanel1;
	private JLabel lblPicture;
	private JLabel lblHeadline;
	private JLabel txtCity;
	private JLabel txtCountry;
	private JLabel txtBday;
	private JLabel lblCity;
	private JLabel lblCountry;
	private JLabel lblBday;
	private JLabel lblName;

	/**
	 * Creates an instance of pnlUserDetails
	 * @param user the user details to view
	 */
	public pnlUserDetails(UserDetails user){
		initGUI(user);
	}

	/**
	 * initializes the GUI
	 * @param user the user details to view
	 */
	private void initGUI(UserDetails user) {
		try {
			{
				this.setPreferredSize(new java.awt.Dimension(487, 214));
				this.setLayout(null);
				{
					btnBack = new JButton();
					this.add(btnBack);
					btnBack.setText("Back");
					btnBack.setBounds(143, 172, 86, 20);
					btnBack.addActionListener(new ActionListener(){
						public void actionPerformed(ActionEvent e){
							GuiFacade.getInstance().showMainScreen();
						}
					});
				}
				{
					lblName = new JLabel();
					this.add(lblName);
					lblName.setText("Name:");
					lblName.setBounds(40, 55, 87, 14);
				}
				{
					lblBday = new JLabel();
					this.add(lblBday);
					lblBday.setText("Birth Day:");
					lblBday.setBounds(40, 81, 87, 14);
				}
				{
					lblCountry = new JLabel();
					this.add(lblCountry);
					lblCountry.setText("Country:");
					lblCountry.setBounds(40, 107, 87, 14);
				}
				{
					lblCity = new JLabel();
					this.add(lblCity);
					lblCity.setText("City:");
					lblCity.setBounds(40, 133, 87, 14);
				}
				{
					txtName = new JLabel();
					this.add(txtName);
					txtName.setBounds(145, 52, 117, 20);
					txtName.setText(user.getName());
				}
				{
					txtBday = new JLabel();
					this.add(txtBday);
					txtBday.setBounds(145, 78, 117, 20);
					txtBday.setText(user.getBday());
				}
				{
					txtCountry = new JLabel();
					this.add(txtCountry);
					txtCountry.setBounds(145, 104, 117, 20);
					txtCountry.setText(user.getCountry());
				}
				{
					txtCity = new JLabel();
					this.add(txtCity);
					txtCity.setBounds(145, 130, 117, 20);
					txtCity.setText(user.getCity());
				}
				{
					lblHeadline = new JLabel();
					this.add(lblHeadline);
					lblHeadline.setText("User details");
					lblHeadline.setBounds(117, 17, 112, 14);
				}
				{
					jScrollPane1 = new JScrollPane();
					this.add(jScrollPane1);
					jScrollPane1.setBounds(267, 31, 180, 141);
					{
						jPanel1 = new JPanel();
						jScrollPane1.setViewportView(jPanel1);
						BoxLayout jPanel1Layout = new BoxLayout(jPanel1, javax.swing.BoxLayout.X_AXIS);
						jPanel1.setLayout(jPanel1Layout);
						jPanel1.setBounds(267, 31, 180, 141);
						{
							lblPicture = new JLabel();
							jPanel1.add(lblPicture);
							BoxLayout lblPictureLayout = new BoxLayout(lblPicture, javax.swing.BoxLayout.X_AXIS);
							lblPicture.setLayout(lblPictureLayout);
							lblPicture.setPreferredSize(new java.awt.Dimension(166, 134));
							lblPicture.setIcon(new ImageIcon(user.getImg()));
						}
					}
				}
			}
		} catch(Exception e) {
			SecurityHandler.catchException("initializing user details panel", e, false);
			//e.printStackTrace();
		}
	}

}
